package com.seven.commons.db;

import lombok.extern.slf4j.Slf4j;

/**
 * @工程名:common-utils
 * @author: sevenDay
 * @时间: 2019/1/11 11:46
 * @描述: 命名的规范更改
 */
@Slf4j
public class DBColumnUtils {
    /**
     * @descrp:转化为驼峰命名
     * @auther: sevenDay
     * @date: 2019/1/11 14:40
     * @param column :
     * @return : java.lang.String
     */
    public static String columnTohump(String column) {

        StringBuilder result = new StringBuilder();
        if (column == null || column.isEmpty()) {
            return "";
        } else if (!column.contains("_")) {
            return column.substring(0, 1).toLowerCase() + column.substring(1);
        } else {
            String[] columns = column.split("_");
            for (String columnSplit : columns) {
                if (columnSplit.isEmpty()) {
                    continue;
                }
                if (result.length() == 0) {
                    result.append(columnSplit.toLowerCase());
                } else {
                    result.append(columnSplit.substring(0, 1).toUpperCase()).append(columnSplit.substring(1).toLowerCase());
                }
            }
            return result.toString();
        }
    }
    /**
     * @descrp:转化为驼峰命名
     * @auther: sevenDay
     * @date: 2019/1/11 14:40
     * @param property :
     * @return : java.lang.String
     */
    public static String humpToLine(String property){
        if (property == null || property.isEmpty()){
            return"";
        }
        StringBuilder column = new StringBuilder();
        column.append(property.substring(0,1).toLowerCase());
        for (int i = 1; i < property.length(); i++) {
            String s = property.substring(i, i + 1);
            if(!Character.isDigit(s.charAt(0))&&s.equals(s.toUpperCase())){
                column.append("_");
            }
            column.append(s.toLowerCase());
        }
        return column.toString();
    }
}
